package com.kexun.servlet.teacher;

import com.alibaba.fastjson.JSON;
import com.kexun.pojo.Student;
import com.kexun.pojo.Teacher;
import com.kexun.pojo.User;
import com.kexun.service.TeaService;
import com.kexun.service.impl.TeaServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/findScoreAll")
public class findScoreAll extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");


        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");

        String userNum = user.getUserNum();

        String limitStr = request.getParameter("limit");
        String pageStr = request.getParameter("page");
        int limit = Integer.parseInt(limitStr);
        int page = Integer.parseInt(pageStr);


        TeaService ts = new TeaServiceImpl();
        Map<String,Object> map =  ts.findStuScore(userNum,limit,page);

        System.out.println(map);
        if (map!=null){
            String s = JSON.toJSONString(map);
            response.getWriter().print(s);
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
